<div class="row animate fadeIn">
    <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>Edit</i></h5>
        <div class="ibox-tools">
             <button class="btn btn-primary btn-sm save-btn-tab" id="update_btn">Save</button>
             <a id="cancel_edit" class="btn btn-sm btn-outline btn-info cancel-btn-tab">Cancel</a>
        </div>
     </div>
     <div class="ibox-content">
     <form id="read_tasks_edit" class="form-horizontal">
     <?php foreach($reads as $r): ?>
      <input type="hidden" value="<?php echo $r->task_id; ?>" name="task_id">
      <div class="form-group">
                <label class="col-xs-4 control-label">Tasks Name *</label>
                <div class="col-xs-5">
                    <input type="text" class="form-control" value="<?php echo $r->task_name; ?>" name="task_name">
                </div>
             </div>
             <div class="form-group">
                <label class="col-xs-4 control-label">Zones *</label>
                <div class="col-xs-5">
                    <select name="zone" class="form-control chosen" id="">
                        <option value="">--</option>
                        <?php foreach ($zones as $key): ?>
                            <option <?php echo ($r->zone == $key->zone_name ? 'selected':''); ?> value="<?php echo $key->zone_name; ?>"><?php echo $key->zone_name; ?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label">Meter Reader *</label>
                <div class="col-xs-5">
                    <select disabled name="meter_reader" class="form-control chosen" id="">
                        <option value="">--</option>
                        <?php foreach ($meter_reader as $key): ?>
                            <option <?php echo ($r->reader_id == $key->user_id ? 'selected' : ''); ?> value="<?php echo $key->user_id; ?>"><?php echo $key->name; ?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
            <div class="form-group">
              <label class="col-xs-4 control-label">Sequence: *</label>
              <div class="col-xs-5">
                <div class="input-group m-b">
                  <input name="seq_from" type="text" placeholder="ex: 0" value="<?php echo $r->seq_from; ?>" class="form-control">
                  <span class="input-group-addon">-</span>
                  <input name="seq_to" type="text" placeholder="ex: 1000" value="<?php echo $r->seq_to; ?>" class="form-control">
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-4 control-label">Year-Month: *</label>
              <div class="col-xs-5">
                <div class="input-group m-b">
                  <select name="year" class="form-control chosen">
                    <?php
                    $mon = array('','January','February','March','April','May','June','July','August','September','October','November','December');
                    for($i = date('Y'); $i >= 2010 ; $i--):?>
                      <option <?php echo ($r->month == $i ? 'selected' : ''); ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
                    <?php endfor; ?>
                  </select>
                  <span class="input-group-addon">-</span>
                   <select name="month" class="form-control chosen">
                    <?php for($o = 1; $o <= 12; $o++):?>
                      <option <?php echo ($r->year == $o ? 'selected' : ''); ?> value="<?php echo $o < 10 ? '0'.$o : $o; ?>"><?php echo $mon[$o]; ?></option>
                    <?php endfor; ?>
                 </select>
                </div>
              </div>
            </div>
          <?php endforeach; ?>
        </form>
    </div>
    <!-- row for sequence add -->
 </div>
 <input type="hidden" id="set" value="0">
 <script>
    $(document).ready(function(){
      $('#edit_list_form').data('serialize',$('#edit_list_form').serialize());
      $(".chosen-select").chosen({width:"100%;"});
      var l_id = $('#e_list_id').val();
      $('#c_id').val(l_id);
      var setter =0;

      //================================================
      //
      //        START INITIALIZATION
      //
      //================================================

      $('#read_tasks').data('serialize',$('#read_tasks').serialize()); 
      $(".chosen").chosen({width:"100%;"});
      $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
      });

      //================================================
      //        END INITIALIZATION
      //================================================


      //================================================
      //
      //        START FORM VALIDATION SECTION
      //
      //================================================
      
      $("#read_tasks").validate({
           rules: {
               task_name: {
                   required: true
               },
               zone: {
                   required: true
               },
               seq_from: {
                   required: true
               },
               seq_to: {
                   required: true
               },
               year: {
                   required: true
               },
               month: {
                   required: true
               }
           }
       });

      //================================================
      //        END FORM VALIDATION
      //================================================


      //================================================
      //
      //        START PROCESSING
      //
      //================================================

      $('#update_btn').click(function(event) {
          if($("#read_tasks_edit").valid() == true){
            $.ajax({
              type: "POST",
                url: "<?php echo base_url($this->session->userdata('forajax') . '/update'); ?>",
                cache: false,
                dataType: 'json',
                data: $('#read_tasks_edit').serialize(),
                success: function(e) {
                  $('#update_btn').removeAttr('disabled');
                  if(e[0].err == '1'){
                    notifymsg('danger',e[0].msg);
                  }else{
                    close_edit(); active_search();
                    notifymsg('success','Success Update');
                  }
                },
                beforeSend: function(){
                  $('#update_btn').attr('disabled',true);
                }
            });
          }
      });

      //================================================
      //  END PROCESSING
      //================================================

          function alert_cancel(){
            var setter = 0;
            if($('#e_seq_num').val() != "" || $('#e_list_chg_code').val() != ""){
                setter = 1;
            }
            if($('#edit_list_form').serialize()!=$('#edit_list_form').data('serialize')){
                setter = 1;
            }
            if(setter == 1){
                swal({
                    title: "Are you sure?",
                    text: "Your work will not be save",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Leave",
                    cancelButtonText: "Stay",
                    closeOnConfirm: true,
                    closeOnCancel: true },
                function (isConfirm) {
                    if (isConfirm) {
                        close_edit(); active_search();
                        notifymsg("hide","hide");
                    } else {
                        swal("Cancelled");
                    }
                });
                }else{
                close_edit(); active_search();
                notifymsg("hide","hide");
            }
        }
        $('#cancel_edit').click(function(){
            alert_cancel();
        });
        $('#editX').click(function(){
            alert_cancel();
        });
    });
 </script>